//
//  PublicArticleViewController.m
//  AAIM
//
//  Created by 远的小布丁 on 2020/1/21.
//  Copyright © 2020 AAIM. All rights reserved.
//

#import "PublicArticleViewController.h"
#import "PublicArticleTableViewCell.h"
#import "TZImagePickerController.h"

#import "MWPhotoBrowser.h"
#import "UIImage+Compress.h"
#import "PublicChatBar.h"
#import "PublicQRCodeViewController.h"
#import "PublicMessageDataBase.h"
#import "PublicContentViewController.h"
#import "AudioRecordAnimateView.h"
#import "PublicTextAndPicTableViewCell.h"

@interface PublicArticleViewController ()<UITableViewDelegate,UITableViewDataSource,UITextViewDelegate,PublicChatBarDelegate,UINavigationControllerDelegate,TZImagePickerControllerDelegate,UIImagePickerControllerDelegate>
{
    UIButton * markBtn;
}
@property (nonatomic,strong)UIView * menuBackView;
//@property(nonatomic,strong)LXKeyBoard *keyboard;
@property (nonatomic,strong)UITableView * articleTableView;
//@property (nonatomic,strong)UIView * menuView;
@property (nonatomic, strong) PublicChatBar *chatBar;
@property (nonatomic,strong)NSMutableArray * menuAry;
@property (nonatomic,strong)NSArray * chilas;//子菜单数组
@property (nonatomic,strong)NSMutableArray * dataSouceAry;
// 录音
@property (nonatomic, strong) AudioRecordAnimateView *recordAnimateView;
@end

@implementation PublicArticleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.articleTableView];
    [self setup];
    self.view.backgroundColor=KHEXCOLOR(@"#F4F4F4");
    self.automaticallyAdjustsScrollViewInsets = NO;
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setImage:[UIImage imageNamed:@"icon- 点点"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightBtnDidClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn sizeToFit];
    rightBtn.frame = CGRectMake(0, 0, 44, 44);
    rightBtn.tag = 10001;
    rightBtn.jk_touchAreaInsets  = UIEdgeInsetsMake(10, 10, 10, 10);
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.gk_navRightBarButtonItem = rightItem;
    [[UIApplication sharedApplication].keyWindow addSubview:self.menuBackView];

    _menuAry = [NSMutableArray array];
    _dataSouceAry = [NSMutableArray array];
    [self getMenuListData];
    [self getLocalData];
}

- (void)chatBarRecordAudioViewStartRecord {
    _recordAnimateView = [[AudioRecordAnimateView alloc] init];
    _recordAnimateView.tips = @"松开发送录音";
    [_recordAnimateView show];
}

- (void)chatBarRecordAudioViewStopRecord:(NSString *)path timeLength:(NSInteger)timeLength {
    if (timeLength < 1.0) {
        [_recordAnimateView dismiss];
        [self showTipHudWithText:@"录音时间太短"];
        return;
    }
//    [self sendVoiceMessage:path timeLength:timeLength];
    [_recordAnimateView dismiss];
}
-(void)chatCountdownAnimationWithTime:(NSInteger)time
{
    _recordAnimateView.tips=[NSString stringWithFormat:@"%ld",time];
}
- (void)chatBarRecordAudioViewCancelRecord {
    [_recordAnimateView dismiss];
}

- (void)chatBarChangeMenu:(UIButton *)sender{
    [self removeFromSuperViews];
    if (sender.tag >=1000) {
        [self menuActive:sender];
    }else{
        if (sender.selected) {
            self.chatBar.menuView.hidden = NO;
        }else{
            self.chatBar.menuView.hidden = YES;
        }
    }
    
}

- (void)chatBarDidShowMoreViewAction {
    [self.articleTableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.chatBar.mas_top);
    }];
    [self.articleTableView reloadData];
    [self performSelector:@selector(scrollToBottomRow) withObject:nil afterDelay:0.1];
}

- (void)chatBarPhotoBtnDidClickAction {
    TZImagePickerController *picker = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self pushPhotoPickerVc:YES];
    picker.allowPickingVideo = NO;
    picker.allowPickingOriginalPhoto = NO;
    picker.allowCrop = NO;
    picker.maxImagesCount= 9;
    [self presentViewController:picker animated:YES completion:nil];
}

- (void)chatBarCameraBtnDidClickAction {
    UIImagePickerController *picker = [UIImagePickerController new];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.allowsEditing = NO;
    picker.delegate = self;
    [self presentViewController:picker animated:YES completion:nil];
}

#pragma mark - UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
    [picker dismissViewControllerAnimated:YES completion:nil];
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    image = [image compressSizeOfImageData:image maxSize:100];
    [self sendImageMessage:image];
}
#pragma mark -- TZImagePickerControllerDelegate

- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos {
    //上传照片
    [photos enumerateObjectsUsingBlock:^(UIImage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIImage *compressedImage = [obj compressSizeOfImageData:obj maxSize:100];
        [self sendImageMessage:compressedImage];
    }];
}

// 发送图片
- (void)sendImageMessage:(UIImage *)image {
    // 发送频率限制
    BOOL canSend = [self canSendMessages];
    if (!canSend) {
        [self showTipHudWithText:@"发送过于频繁，请稍后重试"];
        return;
    }

  
}

/**
 限制发送频率
 */
- (BOOL)canSendMessages {
    return YES;
    
}

// 发送语音
- (void)sendVoiceMessage:(NSString *)filePath timeLength:(NSInteger)timeLength {

}

#pragma mark - 键盘通知

- (void)keyBoardWillShow:(NSNotification *)note {
    // 获取用户信息
    NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
    // 获取键盘高度
    CGRect keyBoardBounds  = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat keyBoardHeight = keyBoardBounds.size.height;
    // 获取键盘动画时间
    CGFloat animationTime  = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    // 定义好动作
    void (^animation)(void) = ^void(void) {
        [self.chatBar mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.view).offset(-keyBoardHeight + EMVIEWBOTTOMMARGIN);
        }];
    };
    if (animationTime > 0) {
        [UIView animateWithDuration:animationTime animations:animation completion:^(BOOL finished) {
            [self scrollToBottomRow];
        }];
    } else {
        animation();
    }
}

- (void)keyBoardWillHide:(NSNotification *)note {
    
    
    // 获取用户信息
    NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
    // 获取键盘动画时间
    CGFloat animationTime  = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    // 定义好动作
    void (^animation)(void) = ^void(void) {
        [self.articleTableView reloadData];
        [self.chatBar mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.view);
        }];
    };
    
    if (animationTime > 0) {
        [UIView animateWithDuration:animationTime animations:animation];
    } else {
        animation();
    }
    
}

- (void)scrollToBottomRow{
    [self.articleTableView reloadData];
        dispatch_async(dispatch_get_main_queue(), ^{
             //刷新完成

         if (self.dataSouceAry.count > 0) {
                NSInteger toSection = self.dataSouceAry.count - 1;
                NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:0 inSection:toSection];
                [self.articleTableView scrollToRowAtIndexPath:toIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
              
            }
         });
}

-(BOOL)inputView:(UITextView *)inputView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text userIdsArray:(NSMutableArray *)userIdsArray
{
    if ([text isEqualToString:@"\n"]) { // 回车发送
        [self sendTextMessage:inputView.text];
        return NO;
    } else if ([text length] == 0) {
        
    }
    return YES;
}

#pragma mark - Send Message

// 发送文本
- (void)sendTextMessage:(NSString *)text {
    [self.chatBar clearInputViewText];
    [self removeFromSuperViews];
    if ([NSObject ldy_isEmpty:text]) {
        [self showTipHudWithText:@"请输入内容"];
        return;
    }
   
    ChildMenusModel * childMeModel = [ChildMenusModel new];
    childMeModel.describe = text;
    childMeModel.name = [LoginManager shareLoginManager].userModel.nickname;
    childMeModel.head = [LoginManager shareLoginManager].userModel.head;
    childMeModel.messageDirection = MessageDirectionSend;
    childMeModel.timestamp = [[CommonTools currentTimeStr] integerValue];
    childMeModel.messageType = PublicMessageTypeText;
    childMeModel.publicUdid = self.publicUdid;
    
    [[PublicMessageDataBase sharePublicMessageDataBase] insertMessage:childMeModel];
    [self.dataSouceAry addObject:childMeModel];
    [self scrollToBottomRow];
    [_chatBar sendSuccessClearUserdata];
}



- (void)getLocalData{

  NSArray * dataAry = [[PublicMessageDataBase sharePublicMessageDataBase]queryAllMessagesWithPublicUdid:_publicUdid];
    [_dataSouceAry addObjectsFromArray:dataAry];
    [self scrollToBottomRow];
}

- (void)getMenuListData{
    KWeakSelf;
    [RequestData PostPublicMenuListWithToken:[LoginManager shareLoginManager].userModel.token userUUid:[LoginManager shareLoginManager].userModel.uuid withPublicUDID:_publicUdid Success:^(NSDictionary * _Nonnull Dict) {
        NSLog(@"菜单：%@",Dict);
        NSArray * dataAry = Dict[@"data"];
        if ([Dict[@"code"] integerValue] == 200 && dataAry.count !=0) {
            for (NSDictionary * dic in dataAry) {
                MenuModel * model = [MenuModel mj_objectWithKeyValues:dic];
                NSArray * childs = model.childs;
                for (NSDictionary * chilaDic in childs) {
                    model.retweetedModel = [MenuModel mj_objectWithKeyValues:chilaDic];
                }
               
                [weakSelf.menuAry addObject:model];
            }
            [self setMenuData];
        }
        
    } failure:^(NSString * _Nonnull errMsg) {
        NSLog(@"请求菜单出错%@",errMsg);
    }];
}

- (void)setMenuData{
    for (UIButton * btn in self.chatBar.menuView.subviews) {
        if (btn.tag>=1000) {
            if (_menuAry.count == 3) {
                [_menuAry enumerateObjectsUsingBlock:^(MenuModel * model, NSUInteger idx, BOOL * _Nonnull stop) {
                    if (btn.tag == idx +1000) {
                        [btn setTitle:model.title forState:UIControlStateNormal];
                        if (model.childs.count != 0) {
                            [btn setImage:[UIImage imageNamed:@"小菜单"] forState:UIControlStateNormal];
                        }
                    }
                }];
            }
        }
    }
}

-(void)rightBtnDidClickAction:(UIButton*)sender
{
    self.menuBackView.hidden = sender.selected;
    sender.selected = !sender.selected;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

  
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.menuBackView.hidden = YES;
    
}
-(void)setup{
    if (_pageType != 1) {
        self.chatBar = [[PublicChatBar alloc] init];
        self.chatBar.delegate = self;
        [self.view addSubview:self.chatBar];
        [self.chatBar mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view);
            make.right.equalTo(self.view);
            make.bottom.equalTo(self.view);
            make.height.offset(40.f+EMVIEWBOTTOMMARGIN);
        }];
        [self.articleTableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.gk_navigationBar.mas_bottom);
            make.left.equalTo(self.view);
            make.right.equalTo(self.view);
            make.bottom.equalTo(self.chatBar.mas_top);
        }];
    }else{
    // 视图

      [self.articleTableView mas_makeConstraints:^(MASConstraintMaker *make) {
          make.top.equalTo(self.gk_navigationBar.mas_bottom);
          make.left.equalTo(self.view);
          make.right.equalTo(self.view);
          make.bottom.equalTo(self.view);
      }];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _dataSouceAry.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (_dataSouceAry.count != 0) {
     return 1;
    }else{
        return 0;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ChildMenusModel * model = _dataSouceAry[indexPath.section];
   
        PublicTextAndPicTableViewCell * cell;
    PublicArticleTableViewCell * articleCell;
        if (model.messageType == PublicMessageTypeText) {
//            文字消息
            cell = [tableView dequeueReusableCellWithIdentifier:@"publicTextContent"];
            if (!cell) {
                cell = [[PublicTextAndPicTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"publicTextContent"];
            }
            cell.model = model;
        }else if (model.messageType == PublicMessagePicText){
//            图片消息
            cell = [tableView dequeueReusableCellWithIdentifier:@"publicPicContent"];
            if (!cell) {
                cell = [[PublicTextAndPicTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"publicPicContent"];
            }
            cell.model = model;
        }else if (model.messageType == PublicMessagePicAndText){
//            图文信息
            articleCell = [tableView dequeueReusableCellWithIdentifier:@"PublicArticleCell"];
            if (!articleCell) {
                articleCell = [[PublicArticleTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PublicArticleCell" withType:@"PublicArticleCell"];
            }
            articleCell.selectionStyle = UITableViewCellSelectionStyleNone;
            articleCell.model = model;
             return articleCell;
        }
    cell.line.hidden =YES;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
   return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    ChildMenusModel * childModel = _dataSouceAry[indexPath.section];
    if (childModel.pic) {
      return [self calculationCellHeight:childModel.describe withMessageType:childModel.messageType]+208.f;
    }else{
        return [self calculationCellHeight:childModel.describe withMessageType:childModel.messageType];
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UILabel*timeLbl = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, kScreenWidth-30, 40)];
    ChildMenusModel * model = _dataSouceAry[section];
    timeLbl.textColor = KHEXCOLOR(@"#AFAFAF");
    timeLbl.font = kMainFont(12);
    timeLbl.text = [CommonTools getDateStringWithTimeStr:[NSString stringWithFormat:@"%ld",(long)model.timestamp]];
    timeLbl.textAlignment = 1;
    return timeLbl;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ChildMenusModel * childModel = _dataSouceAry[indexPath.section];
    PublicContentViewController * contentVC = [[PublicContentViewController alloc]init];
    contentVC.model = childModel;
    [self.navigationController pushViewController:contentVC animated:YES];
}


- (CGFloat)calculationCellHeight:(NSString *)content withMessageType:(NSInteger)msgType{
    CGRect rect;
    if (msgType == PublicMessageTypeText) {
      rect = [content boundingRectWithSize:CGSizeMake(kScreenWidth - 100, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: kMainFont(15)} context:nil];
    }else{
    rect = [content boundingRectWithSize:CGSizeMake(kScreenWidth - 30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: kMainFont(12)} context:nil];
    }
    return rect.size.height;
}
//子菜单功能
- (void)touchWebView:(UIButton *)sender{
    KWeakSelf;
    markBtn.selected = NO;
     [sender removeFromSuperview];
    MenuModel * model = [MenuModel mj_objectWithKeyValues:_chilas[sender.tag-10000]];
    [RequestData PostPublicMenuInfoWithToken:[LoginManager shareLoginManager].userModel.token userUUid:[LoginManager shareLoginManager].userModel.uuid withPublicID:model.menuID Success:^(NSDictionary * _Nonnull Dict) {
        NSLog(@"子菜单内容：%@",Dict);
        if ([Dict[@"code"] integerValue] == 200) {
                   if (![CommonTools isNull:Dict key:@"data"]) {
                       
                       NSDictionary * dataDic = Dict[@"data"];
                       ChildMenusModel * childModel = [ChildMenusModel mj_objectWithKeyValues:dataDic];
                       if ([childModel.isJump integerValue]) {
                           PublicContentViewController * contentVC = [[PublicContentViewController alloc]init];
                           contentVC.model = childModel;
                           [weakSelf.navigationController pushViewController:contentVC animated:YES];
                       }else{
                           childModel.head = weakSelf.publicModel.head;
                           childModel.name = weakSelf.publicModel.title;
                           childModel.messageDirection = MessageDirectionReceive;
                           childModel.timestamp = [[CommonTools currentTimeStr] integerValue];
                           childModel.messageType = PublicMessagePicAndText;
                           childModel.publicUdid = weakSelf.publicUdid;
                           childModel.publicID = [model.menuID integerValue];
                        
                           [[PublicMessageDataBase sharePublicMessageDataBase] insertMessage:childModel];
                           [weakSelf.dataSouceAry addObject:childModel];
                           
                       }
                   }
            [weakSelf scrollToBottomRow];
               }
    } failure:^(NSString * _Nonnull errMsg) {
        [self showTipHudWithText:errMsg];
    }];
}
//创建子菜单
- (void)creatSmallMenu:(UIButton *)sender{
    markBtn = sender;
    MenuModel * model = _menuAry[sender.tag-1000];
    for (int i=0; i<model.childs.count; i++) {
        MenuModel * newModel = [MenuModel mj_objectWithKeyValues:model.childs[0]];
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.backgroundColor = KHEXCOLOR(@"#FFFFFF");
        button.tag = 10000+i;
        _chilas = model.childs;
        [button setTitleColor:KHEXCOLOR(AllBackColor_titleColor) forState:UIControlStateNormal];
        button.frame = CGRectMake(sender.x, self.chatBar.top-28-38*i, sender.width, 37);
        [button addTarget:self action:@selector(touchWebView:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitle:newModel.title forState:UIControlStateNormal];
        [self.view addSubview:button];
    }
}

- (void)removeFromSuperViews{
    for (UIButton * btn in self.view.subviews) {
        if (btn.tag >=10000) {
            [btn removeFromSuperview];
        }
    }
}

- (void)creatQRCode:(UIButton *)sender{
    [self removeFromSuperViews];
    PublicQRCodeViewController * qrCodeVC = [[PublicQRCodeViewController alloc]init];
    qrCodeVC.gk_navTitle = @"二维码";
    UIButton * btn = [self.view viewWithTag:10001];
    btn.selected = NO;
    qrCodeVC.udid = _publicUdid;
    [self.navigationController pushViewController:qrCodeVC animated:YES];
}

- (void)menuActive:(UIButton *)sender{
    NSInteger tag = sender.tag;
    [self removeFromSuperViews];
    sender.selected = !sender.selected;
    MenuModel * model = _menuAry[tag-1000];
    if (model.childs.count != 0) {
        //有子菜单的创建子菜单
        if (sender.selected) {
            [self creatSmallMenu:sender];
        }else{
            for (UIButton * btn in self.view.subviews) {
                if (btn.tag >=10000) {
                    [btn removeFromSuperview];
                }
            }
        }
    }else{
//        无子菜单，则用菜单id请求数据
        markBtn.selected = NO;
        [self touchGetTableViewData:sender];
    }
  
}

//子菜单功能
- (void)touchGetTableViewData:(UIButton *)sender{
    KWeakSelf;
    MenuModel * model = _menuAry[sender.tag-1000];
    [RequestData PostPublicMenuInfoWithToken:[LoginManager shareLoginManager].userModel.token userUUid:[LoginManager shareLoginManager].userModel.uuid withPublicID:model.menuID Success:^(NSDictionary * _Nonnull Dict) {
        NSLog(@"子菜单内容：%@",Dict);
        if ([Dict[@"code"] integerValue] == 200) {
            if (![CommonTools isNull:Dict key:@"data"]) {
                
                NSDictionary * dataDic = Dict[@"data"];
                ChildMenusModel * childModel = [ChildMenusModel mj_objectWithKeyValues:dataDic];
                if ([childModel.isJump integerValue]) {
                    PublicContentViewController * contentVC = [[PublicContentViewController alloc]init];
                    contentVC.model = childModel;
                    [weakSelf.navigationController pushViewController:contentVC animated:YES];
                }else{
                    childModel.head = weakSelf.publicModel.head;
                    childModel.name = weakSelf.publicModel.title;
                    childModel.messageDirection = MessageDirectionReceive;
                    childModel.timestamp = [[CommonTools currentTimeStr] integerValue];
                    childModel.messageType = PublicMessagePicAndText;
                    childModel.publicUdid = weakSelf.publicUdid;
                    childModel.publicID = [model.menuID integerValue];
                    [[PublicMessageDataBase sharePublicMessageDataBase] insertMessage:childModel];
                    [weakSelf.dataSouceAry addObject:childModel];
                    
                }
            }
            [weakSelf.articleTableView reloadData];
            dispatch_async(dispatch_get_main_queue(), ^{
                //刷新完成
                
                if (self.dataSouceAry.count > 0) {
                    NSInteger toSection = self.dataSouceAry.count - 1;
                    NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:0 inSection:toSection];
                    [self.articleTableView scrollToRowAtIndexPath:toIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
                    
                }
            });
        }
        
             
    } failure:^(NSString * _Nonnull errMsg) {
        [self showTipHudWithText:errMsg];
    }];
}


- (UITableView *)articleTableView{
    if (!_articleTableView) {
        _articleTableView = [[UITableView alloc]init];
        _articleTableView.delegate = self;
        _articleTableView.dataSource = self;
        _articleTableView.tableHeaderView = [UIView new];
        _articleTableView.backgroundColor = KHEXCOLOR(@"#F4F4F4");
        _articleTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _articleTableView;
}



- (UIView *)menuBackView{
    if (!_menuBackView) {
        _menuBackView = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-147.f,self.gk_navigationBar.bottom-6, 128, 36)];

        _menuBackView.layer.cornerRadius = 6;
        _menuBackView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.17].CGColor;
        _menuBackView.layer.shadowOffset = CGSizeMake(4,4);//阴影偏移量
        _menuBackView.layer.shadowOpacity = 1;
        _menuBackView.layer.shadowRadius = 4;
        _menuBackView.backgroundColor = [UIColor whiteColor];
        _menuBackView.hidden  = YES;
        UIButton * creatQRCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        creatQRCodeBtn.frame = CGRectMake(0, 0, _menuBackView.width, _menuBackView.height);
        [creatQRCodeBtn setImage:[UIImage imageNamed:@"erweima"] forState:UIControlStateNormal];
        [creatQRCodeBtn setTitle:@"生成二维码" forState:UIControlStateNormal];
        creatQRCodeBtn.titleLabel.font = kMainFont(16);
        [creatQRCodeBtn setTitleColor:KHEXCOLOR(@"#262B2F") forState:UIControlStateNormal];
        [creatQRCodeBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, -5)];
        [creatQRCodeBtn addTarget:self action:@selector(creatQRCode:) forControlEvents:UIControlEventTouchUpInside];
        [_menuBackView addSubview:creatQRCodeBtn];
    }
    return _menuBackView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@synthesize description;

@synthesize hash;

@synthesize superclass;

@end
